﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>

<script runat="server">

    protected void GridView1_RowEdit(object sender, EventArgs e)
    {

    }

    protected void GridView1_RowDeleting(object sender, EventArgs e)
    {
        
    }

    protected void GridView1_Command(object sender, GridViewCommandEventArgs e)
    {
        int n=Convert.ToInt16(e.CommandArgument);
        if (e.CommandName.Equals("Editar"))
        {
            Response.Redirect("~/rendicion.aspx?Id=" + GridView1.DataKeys[n].Value);
        }
        if (e.CommandName.Equals("comp"))
        {
            Response.Redirect("~/comprobantes.aspx?Id=" + GridView1.DataKeys[n].Value);
        }
        if (e.CommandName.Equals("Det"))
        {
            Response.Redirect("~/detalle.aspx?Id=" + GridView1.DataKeys[n].Value);
        }
    }
</script>

<asp:Content ID="Cont1" ContentPlaceHolderID="Contenedor1" Runat="Server">
    <asp:Button ID="btnAdd" Runat="Server" Text="Agregar" PostBackUrl="~/rendicion.aspx?Id=new" />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
        DataKeyNames="IdRendicion" DataSourceID="SqlDataSource1" EmptyDataText="No hay registros de datos para mostrar."
        ForeColor="#333333" GridLines="None" OnRowEditing="GridView1_RowEdit" OnRowDeleting="GridView1_RowDeleting" OnRowCommand="GridView1_Command">
        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            <asp:BoundField DataField="IdRendicion" HeaderText="N&#250;mero" ReadOnly="True"
                SortExpression="IdRendicion" DataFormatString="{0:00000000}" />
            <asp:BoundField DataField="Fecha" HeaderText="Fecha" SortExpression="Fecha" DataFormatString="{0:dd/MM/yyyy}" />
            <asp:BoundField DataField="Tipo" HeaderText="Tipo" SortExpression="Tipo">
                <ItemStyle HorizontalAlign="Center" />
            </asp:BoundField>
            <asp:BoundField DataField="CC" HeaderText="Centro" SortExpression="CC" />
            <asp:BoundField DataField="Moneda" HeaderText="Moneda" SortExpression="Moneda" />
            <asp:BoundField DataField="Importe" HeaderText="Importe" SortExpression="Importe" DataFormatString="{0:F2}" >
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:ButtonField ButtonType="Image" CommandName="comp" ImageUrl="~/Icons/lup.png" />
            <asp:ButtonField ButtonType="Image" CommandName="Det" ImageUrl="~/Icons/det.png" />
            <asp:ButtonField ButtonType="Image" CommandName="Editar" ImageUrl="~/Icons/edit.png" />
            <asp:CommandField ButtonType="Image" DeleteImageUrl="~/Icons/del.png" DeleteText=""
                ShowDeleteButton="True" />
        </Columns>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:demoConnectionString1 %>"
        DeleteCommand="DELETE FROM [Rendiciones] WHERE [IdRendicion] = @IdRendicion"
        InsertCommand="INSERT INTO [Rendiciones] ([IdRendicion], [IdEmpleado], [IdTipo], [Fecha], [IdCC], [IdMoneda], [Importe]) VALUES (@IdRendicion, @IdEmpleado, @IdTipo, @Fecha, @IdCC, @IdMoneda, @Importe)"
        ProviderName="<%$ ConnectionStrings:demoConnectionString1.ProviderName %>" SelectCommand="SELECT Rendiciones.IdRendicion, Rendiciones.IdEmpleado,case when Rendiciones.IdTipo=1 then 'R' else 'A' end as Tipo, Rendiciones.Fecha, Rendiciones.IdCC, Rendiciones.IdMoneda, Rendiciones.Importe, CentrosCostos.Descripcion AS CC, Monedas.Descripcion AS Moneda FROM Rendiciones INNER JOIN CentrosCostos ON Rendiciones.IdCC = CentrosCostos.IdCC INNER JOIN Monedas ON Rendiciones.IdMoneda = Monedas.IdMoneda"
        UpdateCommand="UPDATE [Rendiciones] SET [IdEmpleado] = @IdEmpleado, [IdTipo] = @IdTipo, [Fecha] = @Fecha, [IdCC] = @IdCC, [IdMoneda] = @IdMoneda, [Importe] = @Importe WHERE [IdRendicion] = @IdRendicion">
        <DeleteParameters>
            <asp:Parameter Name="IdRendicion" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="IdRendicion" Type="Int32" />
            <asp:Parameter Name="IdEmpleado" Type="Int32" />
            <asp:Parameter Name="IdTipo" Type="Int32" />
            <asp:Parameter Name="Fecha" Type="DateTime" />
            <asp:Parameter Name="IdCC" Type="Int32" />
            <asp:Parameter Name="IdMoneda" Type="Int32" />
            <asp:Parameter Name="Importe" Type="Decimal" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="IdEmpleado" Type="Int32" />
            <asp:Parameter Name="IdTipo" Type="Int32" />
            <asp:Parameter Name="Fecha" Type="DateTime" />
            <asp:Parameter Name="IdCC" Type="Int32" />
            <asp:Parameter Name="IdMoneda" Type="Int32" />
            <asp:Parameter Name="Importe" Type="Decimal" />
            <asp:Parameter Name="IdRendicion" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>

